package com.mengfx.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mengfx.bean.Banner;
import com.mengfx.form.HomeBannerForm;
import com.mengfx.mapper.BannerMapper;
import com.mengfx.service.BannerService;
import com.mengfx.service.QiNiuService;

@Service("bannerService")
public class BannerServiceImpl implements BannerService {
	@Autowired
	private BannerMapper bannerMapper;
	
	@Autowired
	private QiNiuService qiNiuService;

	@Override
	public boolean insertBanner(HomeBannerForm form) {
		Banner record = new Banner();
		record.setBannerType(form.getBannerType());
		record.setBannerValue(form.getBannerValue());
		record.setImg(form.getKey());
		return bannerMapper.insertSelective(record) > 0;
	}

	@Override
	public List<Banner> selectBannerList() {
		// TODO Auto-generated method stub
		List<Banner> banners = bannerMapper.selectBannerList();
		for(Banner banner :banners){
			banner.setImg(qiNiuService.resolveUrl(banner.getImg()));
		}
		return banners;
	}

	@Override
	public boolean sortBanner(Map<Long, Integer> map) {
		// TODO Auto-generated method stub
		return bannerMapper.sortBanner(map)>0;
	}

	@Override
	public boolean hideBanner(Long id) {
		return bannerMapper.hideBanner(id) > 0;
	}

}
